/**
 * 
 */
package info.niwota.web;

import java.io.IOException;
import java.net.BindException;
import java.net.ServerSocket;

/**
 * @author qiangli
 *
 */
public class Util {
	private static final int PORT_MAX = 65536;
	private static final int PORT_MIN = 20000;
	
	public static ServerSocket createServerSocket() throws Exception {
		for (int p = PORT_MIN; p < PORT_MAX; p++) {
			try {
				ServerSocket ss = new ServerSocket(p);
				return ss;
			} catch (BindException e) {
				continue;
			} catch (IOException e) {
				throw e;
			}
		}
		return null;
	}
}
